export function getCookie(name) {
    if (!name || typeof name !== 'string') return;
    
    let str = document.cookie;
    let arr = str.split(';');
    let token = '';
    
    for (let item in arr) {
        if(arr[item].indexOf(name) === 0) {
            token =  arr[item].split('=')[1];
        }
    }
    return token;
}

/*
* key cookie名
* value cookie值
* time cookie有效时间，单位s
* */
export function chgCookie(key, value, time) {
    if (!key || typeof key !== 'string') return;
    
    document.cookie = `${key}=${value};expires=${new Date(new Date().getTime() + time * 1000).toGMTString()}`;
}

export function delCookie(key) {
    if (!key || typeof key !== 'string') return;
    
    document.cookie = `${key}=;expires=${new Date(0).toGMTString()}`;
}


